﻿using BCCommon;
using BCCommon.Enums;
using BCCommon.OAEnums;
using BCDto.OA.Common;
using BCDto.OA.TeamWorks.TaskRecord;
using BCDto.OA.TeamWorks.TaskRejectRecord;
using System;
using System.Collections.Generic;

namespace BCService.OA.TeamWorks.TaskRecordService
{
    /// <summary>
    /// 任务记录（基础）
    /// </summary>
    public interface ITaskRecordService
    {
        /// <summary>
        /// 获取任务记录信息
        /// </summary>
        /// <param name="taskRecordNo">任务记录编号</param>
        /// <returns></returns>
        TaskRecordDto GetEntity(string taskRecordNo);

        /// <summary>
        /// 获取任务记录信息
        /// </summary>
        /// <param name="taskRecordNo">任务记录编号</param>
        /// <returns></returns>
        TaskRecordViewDto GetDetailEntity(string taskRecordNo);

        /// <summary>
        /// 分页获取当前人员下的任务列表
        /// </summary>
        /// <param name="executerAdminId">执行人Id</param>
        /// <param name="start">开始日期</param>
        /// <param name="end">结束日期</param>
        /// <param name="handleStatus">处理状态</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="companyId">公司Id</param>
        /// <param name="ascending">是否升序排序</param>
        /// <param name="pageIndex">分页页码</param>
        /// <param name="pageSize">分页页数</param>
        /// <param name="taskStep">任务步骤</param>
        /// <param name="isMyApproved">是否我审批</param>
        /// <returns></returns>
        PageableList<TaskRecordDto> Query(long? executerAdminId, DateTime? start, DateTime? end, OATaskHandleStatus? handleStatus, string sortName, int? companyId, bool? ascending, int pageIndex, int pageSize, int? taskStep = null, bool? isMyApproved = null);

        /// <summary>
        /// 修改处理状态
        /// </summary>
        /// <param name="taskRecordNo">任务记录编号</param>
        /// <param name="handleStatus">处理状态</param>
        /// <returns></returns>
        bool UpdateHandleStatus(string taskRecordNo, OATaskHandleStatus handleStatus);

        /// <summary>
        /// 获取驳回信息列表
        /// </summary>
        /// <param name="adminId"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="sortName"></param>
        /// <param name="companyId">公司Id</param>
        /// <param name="ascending"></param>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        PageableList<TaskRejectRecordViewDto> GetRejectRecords(long? adminId, DateTime? start, DateTime? end, string sortName, int companyId, bool? ascending, int index, int size);

        /// <summary>
        /// 处理有被驳回的任务为完成
        /// </summary>
        /// <param name="taskRecordNo"></param>
        /// <returns></returns>
        bool HandleHasRejectedRecord(string taskRecordNo);

        ///// <summary>
        ///// 获取任务记录
        ///// </summary>
        ///// <param name="workflowActivityInstanceId">工作流活动实例Id</param>
        ///// <returns></returns>
        //IEnumerable<TaskRecordDto> GetTaskRecords(long workflowActivityInstanceId);

        ///// <summary>
        ///// 获取任务驳回及驳回回复记录
        ///// </summary>
        ///// <param name="workflowActivityInstanceId">工作流活动实例Id</param>
        ///// <returns></returns>
        //IEnumerable<TaskRejectRecordDto> GetTaskRejectRecords(long workflowActivityInstanceId);

        /// <summary>
        /// 获取指定的任务单记录信息
        /// </summary>
        /// <param name="applyRecordCode">申请编号</param>
        /// <returns></returns>
        TaskRecordViewDto GetTaskRecordInfo(string applyRecordCode);

        /// <summary>
        /// 处理有被驳回的任务为完成,只更新任务状态
        /// </summary>
        /// <param name="taskRecordNo">任务记录编号</param>
        /// <returns></returns>
        bool HandleHasRejectedRecordByTaskRecordNo(string taskRecordNo);

        /// <summary>
        /// 获取指定的任务单记录信息
        /// </summary>
        /// <param name="workflowActivityInstanceId">工作流活动实例Id</param>
        /// <returns></returns>
        TaskRecordViewDto GetTaskRecordInfoByActivityInstanceId(long workflowActivityInstanceId);

        /// <summary>
        /// 关闭工作流任务
        /// </summary>
        /// <param name="taskRecordNo">任务记录编号</param>
        /// <returns></returns>
        TaskRecordDto UpdateTaskRecordStatusClose(string taskRecordNo);

        PageableList<TaskRecordDto> GetPageableList(string taskRecordNo, int? companyId, long? adminId, string[] workflowKeys, long? workflowActivityInstanceId, string referenceNumber, bool? isMyApproved, DateTime? startDate, DateTime? endDate, OATaskHandleStatus? status, string sortName, bool? ascending, int pageIndex, int pageSize);

        TaskRecordViewDto GetTask(string taskRecordNo);

        IEnumerable<TaskRecordViewDto> GetTasksByReferenceNumber(string referenceNumber);

        //TaskRecordViewDto Approve(string taskRecordNo, GeneralRequestDto requestDto);

        //TaskRecordViewDto Reject(string taskRecordNo, GeneralRequestDto requestDto);

        //TaskRecordViewDto Pause(string taskRecordNo, GeneralRequestDto requestDto);

        //TaskRecordViewDto Close(string taskRecordNo, GeneralRequestDto requestDto);

        IEnumerable<TaskReplyRecordDto> GetTaskReplies(string taskRecordNo);

        TaskReplyRecordDto CreateTaskReply(string taskRecordNo, TaskReplyRecordRequestDto requestDto);

        /// <summary>
        /// 获取今日待处理任务
        /// </summary>
        /// <param name="adminId">任务执行人ID</param>
        /// <param name="roleType">角色类型</param>
        /// <returns></returns>
        IEnumerable<TaskRecordGroupWorkflowTypeDto> GetPendingTaskList(long adminId, RoleType roleType);

        /// <summary>
        /// 获取我发起的任务列表
        /// </summary>
        /// <param name="adminId">任务执行人ID</param>
        /// <param name="roleType">角色类型</param>
        /// <returns></returns>
        IEnumerable<TaskRecordGroupWorkflowTypeDto> GetAppliedTaskList(long adminId, RoleType roleType);

        /// <summary>
        /// 我的任务和进度
        /// </summary>
        /// <param name="adminId">任务执行人ID</param>
        /// <param name="roleType">角色类型</param>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="handleStatus">处理状态</param>
        /// <param name="sortName">排序字段</param> 
        /// <param name="ascending">是否升序排序</param>
        /// <param name="pageIndex">分页页码</param>
        /// <param name="pageSize">分页页数</param>
        /// <returns></returns>
        PageableList<TaskRecordProgressDto>  GetTaskProgressList(long? adminId, RoleType? roleType, DateTime? startDate, DateTime? endDate, OATaskHandleStatus? handleStatus, string sortName, bool? ascending, int pageIndex, int pageSize);

        /// <summary>
        /// 工作流指派错误，任务回滚到上一步
        /// </summary>
        /// <param name="workflowActivityInstanceId">工作流活动步骤实例ID</param>
        void UpdateRollBack(long workflowActivityInstanceId);

        /// <summary>
        /// 关闭指定的工作流任务
        /// </summary>
        /// <param name="taskRecordNo">任务编号</param>
        /// <param name="requestDto">修改备注</param>
        /// <returns></returns>
        bool UpdateCloseWorkflowTask(string taskRecordNo, RemarkRequestDto requestDto);
    }
}
